home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / mindos11.zip / MMIN2DOS.C < prev    next >
C/C++ Source or Header  |  1991-03-22  |  3KB  |  118 lines

  1. /*  mmin2dos.c  -- copy a Minix file into a DOS file */
  2. /*  Copyright 1988,1991 Steven W. Harrold - All rights reserved. */
  3. /*  $Header: MMIN2DOS.C_V 1.3 91/03/19 13:50:17 SWH Exp $ */
  4.  
  5. #include    <stdio.h>
  6. #include    <stdlib.h>
  7. #include    "mfs.h"
  8. #include    "dev.h"
  9.  
  10. READ_BLOCK
  11.  
  12. #define     CR      0x0d
  13. #define     LF      0x0a
  14. #define     CTLZ    0x1a
  15.  
  16.  
  17. /*==================================================================*/
  18. PRIVATE void mwrite (buf, flen, text, outfd)
  19. byte            *buf ;
  20. long            *flen ;
  21. BOOL            text ;
  22. FILE            *outfd ;
  23. {
  24.     int     ll, i ;
  25.  
  26.     ll = (*flen > BLOCK_SIZE) ? BLOCK_SIZE : *flen ;
  27.     *flen -= ll ;
  28.  
  29.     if (text)
  30.     {
  31.         for (i = 0; i < ll; i++, buf++)
  32.         {
  33.             if (*buf == LF)
  34.                 fputc (CR, outfd) ;
  35.             fputc(*buf, outfd) ;
  36.         }
  37.         if (*flen <= 0)
  38.             fputc(CTLZ, outfd) ;
  39.     }
  40.  
  41.     else
  42.         fwrite (buf, 1, ll, outfd) ;
  43.  
  44. } /* mwrite() */
  45.  
  46.  
  47. /*==================================================================*/
  48. void minix_to_dos (text, ip, ddata, outfd)
  49. BOOL            text ;
  50. struct inode    *ip ;
  51. struct devdata  *ddata ;
  52. FILE            *outfd ;
  53. {
  54.     byte        *bp ;
  55.     ushort      ind_block[BLOCK_SIZE/sizeof(ushort)] ;
  56.     ushort      dbl_block[BLOCK_SIZE/sizeof(ushort)] ;
  57.  
  58.     int         lim = BLOCK_SIZE / sizeof(ushort) ;
  59.  
  60.     int         i, j, k, n ;
  61.     int         blkno ;
  62.     byte        buf[BLOCK_SIZE+1] ;
  63.     long        flen ;
  64.  
  65.  
  66.     flen = ip->i_size ;
  67.  
  68.     for (i=0; i<7; i++)
  69.     {
  70.         blkno = ip->i_zone[i] ;
  71.         if (blkno == 0)
  72.             break ;
  73.         read_block(buf, blkno, ddata) ;
  74.         mwrite (buf, &flen, text, outfd) ;
  75.     }
  76.  
  77.     if (ip->i_ind)
  78.     {
  79.         read_block(ind_block, ip->i_ind, ddata) ;
  80.  
  81.         for (i=0; i<lim; i++)
  82.         {
  83.             blkno = ind_block[i] ;
  84.             if (blkno == 0)
  85.                 break ;
  86.             read_block(buf, blkno, ddata) ;
  87.             mwrite (buf, &flen, text, outfd) ;
  88.         }
  89.     }
  90.  
  91.     if (ip->i_dbl_ind)
  92.     {
  93.         read_block(dbl_block, ip->i_dbl_ind, ddata) ;
  94.  
  95.         for (i=0; i<lim; i++)
  96.         {
  97.  
  98.             blkno = dbl_block[i] ;
  99.             if (blkno == 0)
  100.                 break ;
  101.             read_block(ind_block, blkno, ddata) ;
  102.  
  103.             for (j=0; j<lim; j++)
  104.             {
  105.                 blkno = ind_block[j] ;
  106.                 if (blkno == 0)
  107.                     break ;
  108.                 read_block(buf, blkno, ddata) ;
  109.                 mwrite (buf, &flen, text, outfd) ;
  110.             }
  111.         }
  112.     }
  113.  
  114. } /* minix_to_dos() */
  115.  
  116.  
  117. /*---eof---*/
  118.